# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=thefatrat
pkgver=813.b0586d0
pkgrel=1
pkgdesc='Easy tool to generate backdoor and easy tool to post exploitation attack.'
arch=('x86_64')
groups=('blackarch' 'blackarch-automation' 'blackarch-exploitation')
url='https://github.com/Screetsec/TheFatRat'
license=('GPL3')
depends=('exploitdb' 'backdoor-factory' 'metasploit' 'xterm' 'bind-tools' 'gcc'
         'apache' 'gnome-terminal' 'upx' 'ruby-nokogiri' 'openssl' 'imagemagick'
         'ncurses' 'lib32-zlib' 'lsb-release' 'python' 'python-names'
         'jdk8-openjdk' 'jre8-openjdk' 'unzip' 'mingw-w64-gcc' 'sudo' 'dex2jar'
         'android-apktool' 'android-sdk-build-tools' 'mono' 'python2' 'smali')
makedepends=('git')
source=("$pkgname::git+https://github.com/Screetsec/TheFatRat.git")
sha512sums=('SKIP')
options=('!strip')

prepare() {
  cd $pkgname

  sed 's|python|python2|g' -i fatrat
  sed 's|which apache2|which httpd|g' -i fatrat
  sed 's|/etc/init.d/apache2 start|systemctl start httpd|g' -i fatrat
  sed 's|/etc/init.d/apache2 stop|systemctl stop httpd|g' -i fatrat
  sed 's|/etc/init.d/postgresql start|systemctl start postgresql|g' -i fatrat
  sed 's|/etc/init.d/postgresql stop|systemctl stop postgresql|g' -i fatrat
  sed 's|/var/www/html|/srv/http|g' -i fatrat
  sed 's|/var/www|/srv|g' -i fatrat

  cat > "config/config.path" << EOF
********************************************************************************************************
** Configuration Paths for TheFatRat , do not delete anything from this file or program will not work **
**       if you need to reconfig your tools path , then run ./setup.sh in (TheFatRat directory) .     **
********************************************************************************************************
jarsigner
unzip
keytool
/usr/share/thefatrat/tools/android-sdk/zipalign
/opt/android-sdk/build-tools/*/dx
/opt/android-sdk/build-tools/*/aapt
apktool
baksmali
msfconsole
msfvenom
backdoor-factory
searchsploit
EOF
}

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md CHANGELOG.md \
    troubleshoot.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md LICENSE setup.sh

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname"

  chmod +x "$pkgdir/usr/share/$pkgname/fatrat"
  chmod +x "$pkgdir/usr/share/$pkgname/update"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./fatrat
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

